<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加备品计划</title>
    <link rel="stylesheet" href="./lib/layui-v2.6.3/css/layui.css" media="all">
</head>
<body>
<div class="layui-container" style="padding: 20px;">
    <form class="layui-form" id="addForm">
        <div class="layui-form-item">
            <label class="layui-form-label">退役资产编号</label>
            <div class="layui-input-block">
                <input type="text" name="propertyNumber" required lay-verify="required" placeholder="请输入退役资产编号"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">项目编号</label>
            <div class="layui-input-block">
                <input type="text" name="projectNumber" required lay-verify="required" placeholder="请输入项目编号"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">项目名称</label>
            <div class="layui-input-block">
                <input type="text" name="projectName" required lay-verify="required" placeholder="请输入项目名称"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">物料描述</label>
            <div class="layui-input-block">
                <input type="text" name="description" required lay-verify="required" placeholder="请输入物料描述"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <select name="status" lay-verify="required">
                    <option value="">请选择</option>
                    <option value="0">未完成</option>
                    <option value="1">已完成</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<script src="./lib/layui-v2.6.3/layui.js"></script>
<script>
    layui.use(['form', 'layer', 'jquery'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;

        // 监听提交事件
        form.on('submit(formDemo)', function (data) {
            $.ajax({
                url: '/plan/spare/add',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(data.field),
                success: function (res) {
                    if (res.code === 0) {
                        layer.msg('添加成功');
                        // 关闭弹窗并刷新表格
                        parent.location.reload();
                    } else {
                        layer.msg('添加失败：' + res.msg);
                    }
                },
                error: function () {
                    layer.msg('网络异常，请稍后再试');
                }
            });
            return false; // 阻止表单跳转
        });
    });
</script>
</body>
</html>
